/**
 * 判断是否是昨天
 * @param time 时间戳
 */
function isYesterday(time: number): Boolean {
    const date = new Date();
    const year = date.getFullYear();
    const month = date.getMonth() + 1;
    const day = date.getDate();
    const today = `${year}/${month}/${day}`;
    const todayTime = new Date(today).getTime(); // 当天凌晨的时间
    const yesterdayTime = new Date(todayTime - 24 * 60 * 60 * 1000).getTime(); // 昨天凌晨的时间
    return time < todayTime && yesterdayTime <= time;
}

/**
 * 判断是否是前天
 * @param time 时间戳
 */
function isLastYesterday(time: number): Boolean {
    const twentyFourHours = 24 * 60 * 60 * 1000;
    const fortyEightHours = 24 * 60 * 60 * 1000 * 2;
    const date = new Date();
    const year = date.getFullYear();
    const month = date.getMonth() + 1;
    const day = date.getDate();
    const today = `${year}/${month}/${day}`;
    const todayTime = new Date(today).getTime(); // 当天凌晨的时间
    const yesterdayTime = new Date(todayTime - twentyFourHours).getTime(); // 昨天凌晨的时间
    const lastYesterdayTime = new Date(todayTime - fortyEightHours).getTime(); // 昨天凌晨的时间
    return time < yesterdayTime && lastYesterdayTime <= time;
}

/**
 * 判断是否是去年
 * @param time 时间戳
 */
function isLastYear(time: number): Boolean {
    const year = new Date().getFullYear();
    const lastYear = new Date(time).getFullYear();
    return (year - lastYear) === 1;
}

export { isYesterday, isLastYesterday, isLastYear }